/**
 * Created by 1250052380@qq.com on 2017/6/12.
 */
app.directive('scrollHeight',function($window){
    return{
        restrict:'AE',
        link:function(scope,element,attr){
            element[0].style.height=($window.innerHeight-55)+'px';
        }
    }
});
app.directive('hideTabs', function ($rootScope) {
    return {
        restrict: 'A',
        link: function (scope, element, attributes) {

            scope.$on('$ionicView.beforeEnter', function () {

                scope.$watch(attributes.hideTabs, function (value) {
                    $rootScope.hideTabs = 'tabs-item-hide';
                });
            });

            scope.$on('$ionicView.beforeLeave', function () {
                scope.$watch(attributes.hideTabs, function (value) {
                    $rootScope.hideTabs = 'tabs-item-hide';
                });
                scope.$watch('$destroy', function () {
                    $rootScope.hideTabs = false;
                })

            });
        }
    };
});
app.directive('myTextarea', function() {

    return {

        require: 'ngModel',

        link: function(scope, ele, attrs, modelController) {

            var text = attrs.myTextarea;
            var placeholder = attrs.placeholder;

            var alltext = text + ' ' + placeholder;

            ele.attr('placeholder', alltext);

            ele.on('focus', function() {
                if (!modelController.$modelValue) {
                    setVal(text);
                }

            });

            ele.on('blur', function() {
                if (modelController.$modelValue === text) {
                    setVal('');
                }
            });

            function setVal(v) {
                modelController.$setViewValue(v);
                modelController.$render();
            }

        }

    }

});